const checkCalculatorParameters = (x, y) => {
    if (isNaN(x))
        throw new Error(`${x} should be number type.`);
    if (isNaN(y))
        throw new Error(`${y} should be number type.`);
    return [x, y];
}

export const calculator = {
    add: (x, y) => {
        let [x2, y2] = checkCalculatorParameters(x, y);
        return x2 + y2;
    },
    sub: (x, y) => {
        let [x2, y2] = checkCalculatorParameters(x, y);
        return x2 - y2;
    }
}

export const getCNWeekDay = (weekDay) => {
    if (isNaN(weekDay))
        weekDay = (new Date()).getDay();

    switch (weekDay) {
        case 0: return '星期天';
        case 1: return '星期一';
        case 2: return '星期二';
        case 3: return '星期三';
        case 4: return '星期四';
        case 5: return '星期五';
        case 6: return '星期六';
        default: throw new Error(`Unkown weekday=${weekDay}`);
    }
}